package Netloadin;

use WWW::Mechanize;

sub upload
{
	my $local_file = shift;
    my $hoster_config = shift;

    my $mech = WWW::Mechanize->new();

    my $cookie_jar = HTTP::Cookies->new(
            file => $::spreader_cookie_dir."netloadin.dat",
            autosave => 1,
        );

    $mech->cookie_jar($cookie_jar);

    $tmp = $mech->get("http://www.netload.in/");

    if($tmp->content =~ /name=\"txtuser\"/g)
    {
    	$mech->form_number(1);
    	$mech->field("txtuser" => $hoster_config->{'username'});
    	$mech->field("txtpass" => $hoster_config->{'password'});
    	$mech->field("txtcheck" => "login");
    	$mech->field("txtlogin" => "");
    	$mech->click("txtlogin");

        $tmp = $mech->get("http://www.netload.in/");
    }
	
    $textbox_content =  "ftp://".$::spreader_ftp_user.":".$::spreader_ftp_pwd."\@".$::spreader_ftp_ip.$::spreader_ftp_path.$local_file."\n";

    $mech->form_number(1);
    $mech->field("remote_file" => $textbox_content);
    $mech->submit();

    my @content = $mech->content;
    foreach (@content) {
		if ($_ =~ /(http:\/\/netload\.in\/.*?\.htm)/) {
    		return $1;
    	}
		else
		{
			#print $_ . "\n";
		}
    }

    return "FEHLER BEIM UPLOAD VON ". $local_file;
}

1;